package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojp.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    /**
     * 部门类表查询
     * @return
     */
    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }
    /**
     * 部门删除
     * @param deptId
     */
    @Override
    public void delete(Integer deptId) {
        deptMapper.delete(deptId);
        System.out.println("删除部门"+deptId);
    }
    /**
     * 新增部门
     * @param dept
     */
    public void save (Dept dept){
        //补全基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //保存部门
        deptMapper.save(dept);
    }

    /**
     * 根据id查询部门
     *
     * @param id
     * @return
     */
    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }
    /**
     * 修改部门
     * @param dept
     */
    /**
     * 修改部门
     *
     * @param dept
     */
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}